# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: bk.py
"""
# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: login.py
"""

import requests,execjs,json

headers = {
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Content-Type": "application/json;charset=UTF-8",
    "Origin": "https://bj.ke.com",
    "Referer": "https://bj.ke.com/",
    "Sec-Fetch-Site": "same-site",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
}

def get_size():
    url1 = 'https://clogin.ke.com/authentication/initialize'
    data = {'service': "https://ajax.api.ke.com/login/login/getuserinfo",'version': "2.0"}
    res = requests.post(url1,data=json.dumps(data),headers=headers)
    if res.status_code == 200:
        return res

def login(pwd):
    id = get_size().json().get('loginTicketId')
    print(id)
    with open('x2.js','r',encoding='utf-8') as f:
        pwd1 = execjs.compile(f.read()).call('get_passwrod',pwd)
    data = {
        "accountSystem": "customer",
        "context": {},
        'credential':{
            'encodeVersion': "2",
            'password': pwd1,
            'username': "19918976328",
        },
        'loginTicketId':id,
        'mainAuthMethodName': "username-password",
        'service': "https://ajax.api.ke.com/login/login/getuserinfo",
        "srcId":"eyJ0Ijoie1wiZGF0YVwiOlwiNjZiYjk5ZTc3MjBmMDE3MmEyZTZlNmU2OGQ3NmRiZWYyNDJkMzQzNjM4YzZhZWQ1YjUwODBiNDY2ZTg0Y2I2NWY3NWI3MjRkMjhmZDZkMDg4M2U5NmY4MzJhZTExYTY0YzVhZDljMWYyZTliMTNjY2E3ZWQxMzJiM2I1YmNhOTdjYWRhMmNkNTllOWExNmU4YjEyMDI0ZmE4MzdjMzAzYTEwNGQ3NTQ1OWIwZDU5MzIwMGQzNzNjNWY5OTYyY2JhZjBlNGQ3M2IzMmFjYzg0ZmQzNmY2YmRjZThiM2FmMjY2YWMxZGU0ZTEwZjU0ODQyMjAxNjFmY2ExZTBkOGJlM1wiLFwia2V5X2lkXCI6XCIxXCIsXCJzaWduXCI6XCJjM2ExYmRjM1wifSIsInIiOiJodHRwczovL2JqLmtlLmNvbS8iLCJvcyI6IndlYiIsInYiOiIwLjEifQ",
                'ticketMaxAge': 604800,
                'version': "2.0",
    }
    url = "https://clogin.ke.com/authentication/authenticate"
    response = requests.post(url, headers=headers,  data=json.dumps(data))
    print(response.text)
login('AA123451231236')


